package P150;

import java.util.HashMap;

import java.util.Map;
/**
 * @author LiangMu
 * @version \$Id: P41.java, v 0.1, 2024年07月06日 02:05 LiangMu Exp $$
 */
public class P41 {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            int key = target - num;
            if (map.containsKey(key)) {
                return new int[]{i, map.get(key)};
            } else {
                map.put(num, i);
            }
        }
        throw new RuntimeException();
    }

}
